<script>
    const { createApp } = Vue;
    const app = createApp({
        data() {
            return {
                //是否正在加载中
                canLoad: true,
                loading: false,
                //更多列表数据
                list: {
                    rows: 0,
                    page: 1,
                    pages: 0,
                    list: []
                }
            }
        },
        mounted() {

        },
        methods: {
            dateFormat(time, format) {
                let date = new Date();
                date.setTime(time * 1000);
                //
                let formatList = {
                    "Y": date.getFullYear(),
                    "m": date.getMonth() + 1,
                    "d": date.getDate(),
                    "H": date.getHours(),
                    "i": date.getMinutes(),
                    "s": date.getSeconds()
                };
                for (let f in formatList) {
                    format = format.replace("%" + f, formatList[f]);
                }
                return format;
            },
            getList() {
                if (this.loading || !this.canLoad) {
                    return;
                }
                let page = this.list.page + 1;
                this.loading = true;
                let self = this;
                axios.get("{url url='/cms/api/archive/list'}", {
                    params: {
                        page,
                        total: "{$total|default:20}",
                        tags: "{$tags|default:''}",
                        excludeId: "{$excludeId|default:''}"
                    }
                }).then(({ data }) => {
                    self.loading = false;
                    if (data.error === 0) {
                        self.list.rows = data.data.rows;
                        self.list.pages = data.data.pages;
                        self.list.page = data.data.page;
                        self.list.list = self.list.list.concat(data.data.list);
                        if (data.data.page >= data.data.pages) {
                            self.canLoad = false;
                        }
                    }
                }).catch(() => {
                    //加载失败
                    self.loading = false;
                });
            }
        }
    });
    const vm = app.mount("#{$div|default:'vue-outlet'}");
</script>